//
//  TempDebugTool.swift
//  ANOA
//
//  Created by 邱仙凯 on 2023/3/21.
//  Copyright © 2023 zwb. All rights reserved.
//

import UIKit
#if DEBUG 
import DoraemonKit
class TempDebugTool:DoraemonBaseViewController {
    
    override func needBigTitleView() -> Bool {
        return true
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        setup()
    }
    var segmenteControl1 : UISegmentedControl!
    var segmenteControl2 : UISegmentedControl!
    lazy var enterf1:UITextField = {
        let btn = UITextField()
        btn.backgroundColor = UIColor(kshex: "f5f5f5")
        btn.placeholder = "模块id"
        return btn
    }()
    lazy var enterf2:UITextField = {
        let btn = UITextField()
        btn.backgroundColor = UIColor(kshex: "f5f5f5")
        btn.placeholder = "目录名称"
        return btn
    }()
    lazy var enterBtn:UIButton = {
        let btn = UIButton()
        btn.setTitle("临时模块入口", for: .normal)
        btn.setTitleColor(Theme.primaryColor(), for: .normal)
        btn.layer.cornerRadius = 5
        btn.layer.borderColor = Theme.primaryColor().cgColor
        btn.layer.borderWidth = 1
        return btn
    }()
    
    
    lazy var dicBtn:UIButton = {
        let btn = UIButton()
         btn.setTitle("主细表数据", for: .normal)
        btn.setTitleColor(Theme.primaryColor(), for: .normal)
        btn.layer.cornerRadius = 5
        btn.layer.borderColor = Theme.primaryColor().cgColor
        btn.layer.borderWidth = 1
        return btn
    }()
    lazy var oridicBtn:UIButton = {
        let btn = UIButton()
         btn.setTitle("备份主细表", for: .normal)
        btn.setTitleColor(Theme.primaryColor(), for: .normal)
        btn.layer.cornerRadius = 5
        btn.layer.borderColor = Theme.primaryColor().cgColor
        btn.layer.borderWidth = 1
        return btn
    }()
    lazy var effectBtn:UIButton = {
        let btn = UIButton()
        
        btn.setTitle("影响字段", for: .normal)
        btn.setTitleColor(Theme.primaryColor(), for: .normal)
        btn.layer.cornerRadius = 5
        btn.layer.borderColor = Theme.primaryColor().cgColor
        btn.layer.borderWidth = 1
        return btn
    }()
    lazy var tempBtnM:UIButton = {
        let btn = UIButton()
        btn.setTitle("主表模板", for: .normal)
        btn.setTitleColor(Theme.primaryColor(), for: .normal)
        btn.layer.cornerRadius = 5
        btn.layer.borderColor = Theme.primaryColor().cgColor
        btn.layer.borderWidth = 1
        return btn
    }()
    
    lazy var tempBtnD_prepare:UIButton = {
        let btn = UIButton()
        btn.setTitle("预备细表模板（仅显示）", for: .normal)
        btn.titleLabel?.font = UIFont.systemFont(ofSize: 12)
        btn.setTitleColor(Theme.primaryColor(), for: .normal)
        btn.layer.cornerRadius = 5
        btn.layer.borderColor = Theme.primaryColor().cgColor
        btn.layer.borderWidth = 1
        return btn
    }()
    
    lazy var tempBtnD:UIButton = {
        let btn = UIButton()
        btn.setTitle("当前细表模板", for: .normal)
        btn.setTitleColor(Theme.primaryColor(), for: .normal)
        btn.layer.cornerRadius = 5
        btn.layer.borderColor = Theme.primaryColor().cgColor
        btn.layer.borderWidth = 1
        return btn
    }()
    lazy var tempBtnD_show:UIButton = {
        let btn = UIButton()
        btn.setTitle("当前细表模板(仅显示)", for: .normal)
        btn.titleLabel?.font = UIFont.systemFont(ofSize: 12)
        btn.setTitleColor(Theme.primaryColor(), for: .normal)
        btn.layer.cornerRadius = 5
        btn.layer.borderColor = Theme.primaryColor().cgColor
        btn.layer.borderWidth = 1
        return btn
    }()
    lazy var menuBtn:UIButton = {
        let btn = UIButton()
        btn.setTitle("菜单主模板", for: .normal)
        btn.setTitleColor(Theme.primaryColor(), for: .normal)
        btn.layer.cornerRadius = 5
        btn.layer.borderColor = Theme.primaryColor().cgColor
        btn.layer.borderWidth = 1
        return btn
    }()
    lazy var filterBtn:UIButton = {
        let btn = UIButton()
        btn.setTitle("过滤条件模板", for: .normal)
        btn.setTitleColor(Theme.primaryColor(), for: .normal)
        btn.layer.cornerRadius = 5
        btn.layer.borderColor = Theme.primaryColor().cgColor
        btn.layer.borderWidth = 1
        return btn
    }()
    lazy var itemBtn:UIButton = {
        let btn = UIButton()
        btn.setTitle("控件堆栈", for: .normal)
        btn.setTitleColor(Theme.primaryColor(), for: .normal)
        btn.layer.cornerRadius = 5
        btn.layer.borderColor = Theme.primaryColor().cgColor
        btn.layer.borderWidth = 1
        return btn
    }()
    lazy var changeBtn:UIButton = {
        let btn = UIButton()
        btn.setTitle("菜单权限比对", for: .normal)
        btn.setTitleColor(Theme.primaryColor(), for: .normal)
        btn.layer.cornerRadius = 5
        btn.layer.borderColor = Theme.primaryColor().cgColor
        btn.layer.borderWidth = 1
        return btn
    }()
    
    lazy var ppBtn:UIButton = {
        let btn = UIButton()
        btn.setTitle("配置菜单查看", for: .normal)
        btn.setTitleColor(Theme.primaryColor(), for: .normal)
        btn.layer.cornerRadius = 5
        btn.layer.borderColor = Theme.primaryColor().cgColor
        btn.layer.borderWidth = 1
        return btn
    }()
    lazy var yyyBtn:UIButton = {
        let btn = UIButton()
        btn.setTitle("渔美康审批编辑字段", for: .normal)
        btn.setTitleColor(Theme.primaryColor(), for: .normal)
        btn.layer.cornerRadius = 5
        btn.layer.borderColor = Theme.primaryColor().cgColor
        btn.layer.borderWidth = 1
        return btn
    }()
    lazy var zzzBtn:UIButton = {
        let btn = UIButton()
        btn.setTitle("渔美康审批只读字段", for: .normal)
        btn.setTitleColor(Theme.primaryColor(), for: .normal)
        btn.layer.cornerRadius = 5
        btn.layer.borderColor = Theme.primaryColor().cgColor
        btn.layer.borderWidth = 1
        return btn
    }()
    lazy var cccBtn:UIButton = {
        let btn = UIButton()
        btn.setTitle("渔美康审批所有字段", for: .normal)
        btn.setTitleColor(Theme.primaryColor(), for: .normal)
        btn.layer.cornerRadius = 5
        btn.layer.borderColor = Theme.primaryColor().cgColor
        btn.layer.borderWidth = 1
        return btn
    }()
    
    func setup() {
        self.title = "动态模板辅助"
        
        
        
        segmenteControl1 = UISegmentedControl(items: ["草稿版菜单","定稿版菜单"])
        segmenteControl1.addSegmentChangeClosure { segment in
            if  segment.selectedSegmentIndex == 0 {
                TempUDTool.shared.SetDynamicMenuFlag("test")
            } else {
                TempUDTool.shared.SetDynamicMenuFlag("product")
            }
        }
        segmenteControl1.selectedSegmentIndex = TempUDTool.shared.GetDynamicMenuFlag() == "test" ? 0 : 1
        self.view.addSubview(segmenteControl1)
        segmenteControl1.snp.makeConstraints { make in
            make.centerX.equalTo(self.view)
            make.top.equalTo(self.view).offset(100)
            make.width.equalTo(KSGlobal.screenW - 60)
            make.height.equalTo(35)
        }
        
        segmenteControl2 = UISegmentedControl(items: ["标准显示方式","开启隐藏菜单显示"])
        segmenteControl2.addSegmentChangeClosure { segment in
            if  segment.selectedSegmentIndex == 0 {
                TempUDTool.shared.SetShowType("0")
            } else {
                TempUDTool.shared.SetShowType("1")
            }
        }
        segmenteControl2.selectedSegmentIndex = TempUDTool.shared.GetShowType() == "0" ? 0 : 1
        self.view.addSubview(segmenteControl2)
        segmenteControl2.snp.makeConstraints { make in
            make.centerX.equalTo(self.view)
            make.top.equalTo(self.segmenteControl1.snp.bottom).offset(8)
            make.width.equalTo(KSGlobal.screenW - 60)
            make.height.equalTo(35)
        }
        
        
        
        self.view.addSubview(enterf1)
        enterf1.text = TempUDTool.shared.GetmoduleID()
        enterf1.snp.makeConstraints { make in
            make.left.equalTo(self.view).offset(20)
            make.top.equalTo(self.segmenteControl2.snp.bottom).offset(20)
            make.right.equalTo(self.view.snp.centerX).offset(-10)
            make.height.equalTo(35)
        }
        self.view.addSubview(enterf2)
        enterf2.text = TempUDTool.shared.GetderecNM()
        enterf2.snp.makeConstraints { make in
            make.right.equalTo(self.view).offset(-20)
            make.centerY.equalTo(self.enterf1)
            make.left.equalTo(self.view.snp.centerX).offset(10)
            make.height.equalTo(35)
        }
        
        self.view.addSubview(enterBtn)
        enterBtn.addTouchUpInSideAction { _ in
            
            
            TempUDTool.shared.SetmoduleID(self.enterf1.text.unwrap)
            TempUDTool.shared.SetderecNM(self.enterf2.text.unwrap)
            getTempMenu(id: self.enterf1.text.unwrap,directory_nm: self.enterf2.text.unwrap) { arr in
                
                if arr.count > 0 {
                    let aaa = arr.first!.tempArr
                    
                    let nnaar = aaa.compactMap { onex -> nameAction in
                        var newone = onex
                        let nz = nameAction(name: onex.menu_nm.unwrap) { _ in
                            self.leftNavBackClick(nil)
                            
                            let topViewController = RouterUtils.currentTopViewController()!
                            newone.module_id = self.enterf1.text.unwrap
                            let vc = KSTempListVC()
                            vc.rootTemp = newone
                            topViewController.navigationController?.pushViewController(vc, animated: true)
                            
                            
                            
                        }
                        return nz
                    }
                    
                    alertUtil(self, title: self.enterf2.text.unwrap, operateS: nnaar)
                }
                
                
                
            }
        }
        enterBtn.snp.makeConstraints { make in
            make.centerX.equalTo(self.view)
            make.top.equalTo(enterf1.snp.bottom).offset(10)
            make.width.equalTo(220)
            make.height.equalTo(35)
        }
        self.configLeft()
        self.configRight()
    }
    
    func configLeft() {
        
        self.view.addSubview(dicBtn)
        dicBtn.addTouchUpInSideAction { _ in
            
            self.leftNavBackClick(nil)
            let topViewController = RouterUtils.currentTopViewController()!
            if topViewController.isKind(of: ConfigMenuForm.self) {
                
                let vc = topViewController as! ConfigMenuForm
                let mj = dictionaryToJson(vc.main)
                var dj = ""
                if vc.rootTemp.multiDetailsParams.count > 0 {
                    for i in 0..<vc.rootTemp.multiDetailsTitles.count {
                        dj += "\n 第\(i+1)组细表 \n \(vc.rootTemp.multiDetailsTitles[i])--\(vc.rootTemp.multiDetailsParams[i])"
                         dj +=  vc.detHandler[i].compactMap { dictionaryToJsonBack($0.dic) }.joined(separator: ",")
                        dj += "\n"
                    }
                    
                } else {
                    dj += "\n 唯一一组细表 \n"
                     dj +=  vc.detHandler[0].compactMap { dictionaryToJsonBack($0.dic) }.joined(separator: ",")
                    dj += "\n"
                }
               
                
                let show = "【主表】\n\(mj)  \n 【细表】\n\(dj)"
                alertUtil(vc, title: "主细表数据",message: show, operateS: [nameAction(name: "确定", action: { _ in
                    
                })])
                
            } else {
                KSToast("非配置菜单界面")
            }
            
            
        }
        dicBtn.snp.makeConstraints { make in
            make.left.equalTo(self.view).offset(10)
            make.top.equalTo(enterBtn.snp.bottom).offset(10)
            make.width.equalTo(180)
            make.height.equalTo(35)
        }
        self.view.addSubview(effectBtn)
        effectBtn.addTouchUpInSideAction { _ in
            
            self.leftNavBackClick(nil)
            let topViewController = RouterUtils.currentTopViewController()!
            if topViewController.isKind(of: ConfigMenuForm.self) {
                
                
                let vc = topViewController as! ConfigMenuForm
                
                
                var showM = ""
                for i in 0..<vc.tempEffectM.count {
                    let fff = vc.tempEffectM[i]
                    showM += "\n-------------------\n【\(fff.field_annotation.unwrap)--\(fff.field_nm.unwrap)】\n"
                    
                    for y in 0..<fff.effectArr.count {
                        let ooo = fff.effectArr[y]
                        showM +=  "\n\n【值】\(ooo.field_value.unwrap)\n"
                        for m in 0..<ooo.grammarArr.count {
                            let qqq = ooo.grammarArr[m]
                            showM += "\n【影响key】\n\(qqq.keyword.unwrap)\n"
                            showM += "【影响content】\n\(qqq.contents.joined(separator: "\n"))\n"
                        }
                        
                    }
                    
                }
                
                var showD = "未完善"
//                for i in 0..<vc.tempEffectD.count {
//                    let fff = vc.tempEffectD[i]
//                    showD += "\n-------------------\n【【\(fff.field_annotation.unwrap)--\(fff.field_nm.unwrap)】\n"
//                    
//                    for y in 0..<vc.tempEffectD[i].effectArr.count {
//                        let ooo = fff.effectArr[y]
//                        showD +=  "\n\n【值】\(ooo.field_value.unwrap)\n"
//                        for m in 0..<ooo.grammarArr.count {
//                            let qqq = ooo.grammarArr[m]
//                            showD += "\n【影响key】\n\(qqq.keyword.unwrap)\n"
//                            showD += "【影响content】\n\(qqq.contents.joined(separator: "\n"))\n"
//                        }
//                    }
//                    
//                }
                let finalS = "【主表影响】\n\(showM) \n\n\n\n 【细表影响】\n\(showD)"
                alertUtil(vc, title: "影响字段",message: finalS, operateS: [nameAction(name: "确定", action: { _ in
                    
                })])
                
            } else {
                KSToast("非配置菜单界面")
            }
            
            
        }
        effectBtn.snp.makeConstraints { make in
            make.width.left.equalTo(dicBtn)
             make.top.equalTo(dicBtn.snp.bottom).offset(10)
            make.width.equalTo(220)
            make.height.equalTo(35)
        }
        
        self.view.addSubview(tempBtnM)
        tempBtnM.addTouchUpInSideAction { _ in
            
            self.leftNavBackClick(nil)
            let topViewController = RouterUtils.currentTopViewController()!
            if topViewController.isKind(of: ConfigMenuForm.self) {
                
                
                let vc = topViewController as! ConfigMenuForm
                
                
                var showM = ""
                for i in 0..<vc.mainHandler.count {
                    let model = vc.mainHandler[i].temp!
                    showM += "\n-------------------\n【\(model.field_annotation.unwrap)--\(model.field_nm.unwrap)】\n显示\(model.isFormSHow.unwrap)--必填\(model.is_required.unwrap)--可编辑\(model.isEditEnable.unwrap)\n类型\(model.field_type.unwrap)--最大张数\(model.upload_num_max.unwrap)\n"
                    
                    
                    let ymkzz = model.ymkD_idNameFlag.unwrap
                    if ymkzz != "" {
                        showM += "渔美康定制标识\(ymkzz)\n"
                    }
                    
                    let height = model.field_height.unwrap
                    if height != "" {
                        showM += "高度\(height)\n"
                    }
                    
                    let placeholder = model.placeholder.unwrap
                    if placeholder != "" {
                        showM += "提示文本\(placeholder)\n"
                    }
                    let computed_expression = model.computed_expression.unwrap
                    if computed_expression != "" {
                        showM += "计算公式\(computed_expression)\n"
                    }
                    
                    if  model.pathHandler.path != "" ||
                            model.field_type == TemplateType.dormlovtree.rawValue ||
                            model.field_type == TemplateType.companylovtree.rawValue {
                        showM += "\nLOV:\(model.pathHandler.path)\n"
                        showM += "\n参数1:\(model.pathHandler.comPa.joined(separator: "\n"))\n"
                        showM += "\n参数2:\(model.pathHandler.spePa.joined(separator: "\n"))\n"
                        showM += "\n显示：\(model.lovShowArr.joined(separator: "\n"))\n"
                        showM += "\n回填：\(model.lovBackFillArr.joined(separator: "\n"))\n"
                    }
                    if  model.select_data.unwrap != "" {
                        showM += "\n下拉选：\(model.select_data.unwrap)\n"
                        showM += "\n下拉选回填：\(model.select_field_backfill.unwrap)\n"
                    }
                    if  model.callInterfaceBackArr.count > 0 {
                        showM += "\n调用回填：\(model.callInterfaceBackArr.joined(separator: "\n"))\n"
                    }
                    
                }
                
                alertUtil(vc, title: "主表模板",message: showM, operateS: [nameAction(name: "确定", action: { _ in
                    
                })])
                
            } else {
                KSToast("非配置菜单界面")
            }
            
            
        }
        tempBtnM.snp.makeConstraints { make in
            make.width.left.equalTo(dicBtn)
            make.top.equalTo(effectBtn.snp.bottom).offset(10)
            make.width.equalTo(220)
            make.height.equalTo(35)
        }
        
        
        
        self.view.addSubview(tempBtnD)
        tempBtnD.addTouchUpInSideAction { _ in
            
            self.leftNavBackClick(nil)
            let topViewController = RouterUtils.currentTopViewController()!
            if topViewController.isKind(of: ConfigMenuForm.self) {
                
                
                let vc = topViewController as! ConfigMenuForm
                
                
                var showD = ""
                for i in 0..<vc.detHandler[0].count {
                    showD += "\n----第\(i + 1)条----"
                    for model in vc.detHandler[0][i].temp {
                        
                        showD += "\n【\(model.field_annotation.unwrap)--\(model.field_nm.unwrap)】\n显示\(model.isFormSHow.unwrap)--必填\(model.is_required.unwrap)--可编辑\(model.isEditEnable.unwrap)\n类型\(model.field_type.unwrap)--最大张数\(model.upload_num_max.unwrap)\n"
                        let placeholder = model.placeholder.unwrap
                        if placeholder != "" {
                            showD += "提示文本\(placeholder)\n"
                        }
                        let computed_expression = model.computed_expression.unwrap
                        if computed_expression != "" {
                            showD += "计算公式\(computed_expression)\n"
                        }
                        if model.pathHandler.path != "" {
                            showD += "\nLOV:\(model.pathHandler.path)\n"
                            showD += "\n参数1:\(model.pathHandler.comPa.joined(separator: "\n"))\n"
                            showD += "\n参数2:\(model.pathHandler.spePa.joined(separator: "\n"))\n"
                            showD += "\n显示：\(model.lovShowArr.joined(separator: "\n"))\n"
                            showD += "\n回填：\(model.lovBackFillArr.joined(separator: "\n"))\n"
                            if model.call_port_url.unwrap != "" {
                                showD += "\n后续接口：\(model.call_port_url.unwrap)\n"
                            }
                        }
                        if model.grmmarArr.count > 0 {
                            showD += "\n语法：\(model.grmmarArr.joined(separator: "\n"))\n"
                            
                        }
                        
                    }
                }
                
                alertUtil(vc, title: "细表模板",message: showD, operateS: [nameAction(name: "确定", action: { _ in
                    
                })])
                
            } else {
                KSToast("非配置菜单界面")
            }
            
            
        }
        tempBtnD.snp.makeConstraints { make in
            make.width.left.equalTo(dicBtn)
            make.top.equalTo(tempBtnM.snp.bottom).offset(10)
            make.width.equalTo(220)
            make.height.equalTo(35)
        }
        
        
        self.view.addSubview(tempBtnD_show)
        tempBtnD_show.addTouchUpInSideAction { _ in
            
            self.leftNavBackClick(nil)
            let topViewController = RouterUtils.currentTopViewController()!
            if topViewController.isKind(of: ConfigMenuForm.self) {
                
                
                let vc = topViewController as! ConfigMenuForm
                
                
                var showD = ""
                for i in 0..<vc.detHandler.count {
                    showD += "\n----第\(i + 1)条----"
                    for model in vc.detHandler[0][i].temp {
                        if isShowJ(model,auCombine: vc.tempAuditParamC,exType: vc.excuteType) {
                            showD += "\n【\(model.field_annotation.unwrap)--\(model.field_nm.unwrap)】\n显示\(model.isFormSHow.unwrap)--必填\(model.is_required.unwrap)--可编辑\(model.isEditEnable.unwrap)\n类型\(model.field_type.unwrap)--最大张数\(model.upload_num_max.unwrap)\n"
                            let placeholder = model.placeholder.unwrap
                            if placeholder != "" {
                                showD += "提示文本\(placeholder)\n"
                            }
                            let computed_expression = model.computed_expression.unwrap
                            if computed_expression != "" {
                                showD += "计算公式\(computed_expression)\n"
                            }
                            if model.pathHandler.path != "" {
                                showD += "\nLOV:\(model.pathHandler.path)\n"
                                showD += "\n参数1:\(model.pathHandler.comPa.joined(separator: "\n"))\n"
                                showD += "\n参数2:\(model.pathHandler.spePa.joined(separator: "\n"))\n"
                                showD += "\n显示：\(model.lovShowArr.joined(separator: "\n"))\n"
                                showD += "\n回填：\(model.lovBackFillArr.joined(separator: "\n"))\n"
                                
                            }
                            if model.grmmarArr.count > 0 {
                                showD += "\n语法：\(model.grmmarArr.joined(separator: "\n"))\n"
                                
                            }
                        }
                       
                        
                    }
                }
                
                alertUtil(vc, title: "细表模板(仅显示)",message: showD, operateS: [nameAction(name: "确定", action: { _ in
                    
                })])
                
            } else {
                KSToast("非配置菜单界面")
            }
            
            
        }
        tempBtnD_show.snp.makeConstraints { make in
            make.width.left.equalTo(dicBtn)
            make.top.equalTo(tempBtnD.snp.bottom).offset(10)
            make.width.equalTo(220)
            make.height.equalTo(35)
        }
        
        
        
        self.view.addSubview(menuBtn)
        menuBtn.addTouchUpInSideAction { _ in
            
            self.leftNavBackClick(nil)
            let topViewController = RouterUtils.currentTopViewController()!
            if topViewController.isKind(of: KSTempListVC.self) ||
                topViewController.isKind(of: ConfigMenuForm.self) {
                
                var jS = ""
                if let vcs = topViewController as? KSTempListVC {
                    var finalS  = vcs.rootTemp.dictionaryRepresentation()
                    jS = dictionaryToJson(finalS)
                    if vcs.rootTemp.grmmarArr.count > 0 {
                        jS += "\n语法：\(vcs.rootTemp.grmmarArr.joined(separator: "\n"))\n"
                    }
                    if vcs.rootTemp.defiBtnArr.count > 0 {
                        jS += "\n自定义按钮：\(vcs.rootTemp.defiBtnArr.compactMap{ $0.joined(separator: "\n") }.joined(separator: "\n"))\n"
                    }
                    
                    alertUtil(vcs, title: "菜单主模板",message: jS, operateS: [nameAction(name: "确定", action: { _ in
                        
                    })])
                }
                if let vcs = topViewController as? ConfigMenuForm {
                    var finalS = vcs.rootTemp.dictionaryRepresentation()
                    jS = dictionaryToJson(finalS)
                    if vcs.rootTemp.grmmarArr.count > 0 {
                        jS += "\n语法：\(vcs.rootTemp.grmmarArr.joined(separator: "\n"))\n"
                    }
                    if vcs.rootTemp.defiBtnArr.count > 0 {
                        jS += "\n自定义按钮：\(vcs.rootTemp.defiBtnArr.compactMap{ $0.joined(separator: "\n") }.joined(separator: "\n"))\n"
                    }
                    alertUtil(vcs, title: "菜单主模板",message: jS, operateS: [nameAction(name: "确定", action: { _ in
                        
                    })])
                }
                
                
            } else {
                KSToast("非配置菜单界面")
            }
            
            
        }
        menuBtn.snp.makeConstraints { make in
            make.width.left.equalTo(dicBtn)
            make.top.equalTo(tempBtnD_show.snp.bottom).offset(10)
            make.width.equalTo(220)
            make.height.equalTo(35)
        }
        self.view.addSubview(filterBtn)
        filterBtn.addTouchUpInSideAction { _ in
            
            self.leftNavBackClick(nil)
            let topViewController = RouterUtils.currentTopViewController()!
            if topViewController.isKind(of: KSTempListVC.self) ||
                topViewController.isKind(of: ConfigMenuForm.self) {
                
                var jS = ""
                if let vcs = topViewController as? KSTempListVC {
                    jS = ""
                    if vcs.templateFilter.count > 0 {
                        jS += "\n\(vcs.templateFilter.compactMap{ "\($0.field_type.unwrap)-\($0.field_nm.unwrap)-\($0.field_annotation.unwrap)-\($0.isFormSHow.unwrap)" }.joined(separator: "\n"))\n"
                    }
                    
                    alertUtil(vcs, title: "过滤条件模板",message: jS, operateS: [nameAction(name: "确定", action: { _ in
                        
                    })])
                }
                if let vcs = topViewController as? ConfigMenuForm {
                    var finalS = vcs.rootTemp.dictionaryRepresentation()
                    jS = dictionaryToJson(finalS)
                    if vcs.rootTemp.grmmarArr.count > 0 {
                        jS += "\n语法：\(vcs.rootTemp.grmmarArr.joined(separator: "\n"))\n"
                    }
                    if vcs.rootTemp.defiBtnArr.count > 0 {
                        jS += "\n自定义按钮：\(vcs.rootTemp.defiBtnArr.compactMap{ $0.joined(separator: "\n") }.joined(separator: "\n"))\n"
                    }
                    alertUtil(vcs, title: "菜单主模板",message: jS, operateS: [nameAction(name: "确定", action: { _ in
                        
                    })])
                }
                
                
            } else {
                KSToast("非配置菜单界面")
            }
            
            
        }
        filterBtn.snp.makeConstraints { make in
            make.width.left.equalTo(dicBtn)
            make.top.equalTo(menuBtn.snp.bottom).offset(10)
            make.width.equalTo(220)
            make.height.equalTo(35)
        }
        self.view.addSubview(itemBtn)
        itemBtn.addTouchUpInSideAction { _ in
            
            self.leftNavBackClick(nil)
            let topViewController = RouterUtils.currentTopViewController()!
            if topViewController.isKind(of: GlobalFormVC.self) {
                
                var finalS = ""
                let vc = topViewController as! GlobalFormVC
                finalS += "head -> \(vc.bg.head!.tagx!)\n"
                finalS += "tail -> \(vc.bg.tail!.tagx!)\n"
                finalS += "-------\n"
                var tempIII:FormItem?
                tempIII = vc.bg.head
                var countX = 1
                finalS += "\(countX) -> \(tempIII!.tagx!)\n"
                while tempIII!.nextV.isSome {
                    countX += 1
                    finalS += "\(countX) -> \(tempIII!.nextV!.tagx!)\n"
                    tempIII = tempIII!.nextV
                }
                
                alertUtil(vc, title: "控件堆栈",message: finalS, operateS: [nameAction(name: "确定", action: { _ in
                    
                })])
                
            } else {
                KSToast("非配置菜单界面")
            }
            
            
        }
        itemBtn.snp.makeConstraints { make in
            make.width.left.equalTo(dicBtn)
            make.top.equalTo(filterBtn.snp.bottom).offset(10)
            make.width.equalTo(220)
            make.height.equalTo(35)
        }
        self.view.addSubview(changeBtn)
        changeBtn.addTouchUpInSideAction { _ in
            
            
            self.leftNavBackClick(nil)
            let topViewController = RouterUtils.currentTopViewController()!
            var arr = [(String,String,String)]()
//            for item in LimitsMenus {
//                arr.append(("【服务端菜单】",item.menuNm.unwrap,item.resid.unwrap))
//            }
            for item in MenuPool {
                    arr.append(("【本地菜单】",item.desc.unwrap,item.resId.unwrap))
             }
            
            var allArr = [nameAndModel<(String,String,String)>]()
            for i in 0..<arr.count {
                let one_x = nameAndModel(shows: [arr[i].0,arr[i].1,"【权限id】",arr[i].2], model: arr[i])
                allArr.append(one_x)
            }
            let cle:(nameAndModel<(String,String,String)>)->() = { one in
                
             }
             let vc = KSSingleSelectUtil.initWithNav(title: "权限", allArr: allArr, backClosure: cle)
            topViewController.present_FullScreen(to: vc)
            
            
      
        }
        changeBtn.snp.makeConstraints { make in
            make.width.left.equalTo(dicBtn)
            make.top.equalTo(itemBtn.snp.bottom).offset(10)
            make.width.equalTo(220)
            make.height.equalTo(35)
        }
    }
    func configRight() {
        self.view.addSubview(oridicBtn)
        oridicBtn.addTouchUpInSideAction { _ in
        
             self.leftNavBackClick(nil)
            let topViewController = RouterUtils.currentTopViewController()!
            if topViewController.isKind(of: ConfigMenuForm.self) {
                
                let vc = topViewController as! ConfigMenuForm
                let mj = dictionaryToJson(vc.oriMain)
                let dj =  vc.oriDetArr.compactMap { dictionaryToJsonBack($0) }.joined(separator: ",")
                let show = "【主表】\n\(mj)  \n 【细表】\n\(dj)"
                alertUtil(vc, title: "备份主细表",message: show, operateS: [nameAction(name: "确定", action: { _ in
                    
                })])
                
            } else {
                KSToast("非配置菜单界面")
            }
            
            
            
        }
        oridicBtn.snp.makeConstraints { make in
            make.width.height.centerY.equalTo(dicBtn)
             make.right.equalToSuperview().offset(-10)
         }
        self.view.addSubview(tempBtnD_prepare)
        tempBtnD_prepare.addTouchUpInSideAction { _ in
            
            self.leftNavBackClick(nil)
            let topViewController = RouterUtils.currentTopViewController()!
            if topViewController.isKind(of: ConfigMenuForm.self) {
                
                
                let vc = topViewController as! ConfigMenuForm
                
                
                var showD = "未完善"
              
//                    for model in vc.tempDet {
//                        if vc.isShowJ(model.isFormSHow) {
//                            showD += "\n【\(model.field_annotation.unwrap)--\(model.field_nm.unwrap)】\n显示\(model.isFormSHow.unwrap)--必填\(model.is_required.unwrap)--可编辑\(model.isEditEnable.unwrap)\n类型\(model.field_type.unwrap)\n"
//                            let placeholder = model.placeholder.unwrap
//                            if placeholder != "" {
//                                showD += "提示文本\(placeholder)\n"
//                            }
//                            let computed_expression = model.computed_expression.unwrap
//                            if computed_expression != "" {
//                                showD += "计算公式\(computed_expression)\n"
//                            }
//                            if model.pathHandler.path != "" {
//                                showD += "\nLOV:\(model.pathHandler.path)\n"
//                                showD += "\n参数1:\(model.pathHandler.comPa.joined(separator: "\n"))\n"
//                                showD += "\n参数2:\(model.pathHandler.spePa.joined(separator: "\n"))\n"
//                                showD += "\n显示：\(model.lovShowArr.joined(separator: "\n"))\n"
//                                showD += "\n回填：\(model.lovBackFillArr.joined(separator: "\n"))\n"
//                                
//                            }
//                            if model.grmmarArr.count > 0 {
//                                showD += "\n语法：\(model.grmmarArr.joined(separator: "\n"))\n"
//                                
//                            }
//                        }
// 
//                    }
               
                
                alertUtil(vc, title: "预备细表模板(仅显示)",message: showD, operateS: [nameAction(name: "确定", action: { _ in
                    
                })])
                
            } else {
                KSToast("非配置菜单界面")
            }
            
            
        }
        tempBtnD_prepare.snp.makeConstraints { make in
            make.width.height.equalTo(dicBtn)
            make.top.equalTo(oridicBtn.snp.bottom).offset(10)
             make.right.equalTo(oridicBtn)
         }
        
       
        self.view.addSubview(ppBtn)
        ppBtn.snp.makeConstraints { make in
            make.width.height.equalTo(dicBtn)
            make.top.equalTo(tempBtnD_prepare.snp.bottom).offset(10)
             make.right.equalTo(oridicBtn)
         }
        ppBtn.addTouchUpInSideAction { _ in
            
            self.leftNavBackClick(nil)
           
            let topViewController = RouterUtils.currentTopViewController()!
            var arr = [(String,String,String)]()
            
            
            
            
            
                var sssss = [String]()
            sssss.append("【找不到菜单或者菜单修改没生效，看看发布了没】")
            
                // outer就是当内层循环中 符合条件 这个双层循环完全结束。 (找到菜单)
            outer:for i in 0..<cachedDynamicArray.count {
                sssss.append(cachedDynamicArray[i].0)
                 for onex in cachedDynamicArray[i].1 {
                   
                    // 包含子菜单，
                    if onex.tempArr.count > 0 {
                        sssss.append("     " + onex.directory_nm.unwrap)

                        for chOnex in onex.tempArr {
                             sssss.append( "                    " + chOnex.menu_nm.unwrap + "--" + chOnex.res_id.unwrap)

                         }
                    } else {
                        sssss.append( "     " + onex.menu_nm.unwrap + "--" + onex.res_id.unwrap)
                      
            
                    }
                }
            }
                
       
         
            
            var allArr = [nameAndModel<(String)>]()
            for i in 0..<sssss.count {
                let one_x = nameAndModel(shows: [sssss[i]], model: sssss[i])
                allArr.append(one_x)
            }
            let cle:(nameAndModel<(String)>)->() = { one in
                
             }
             let vc = KSSingleSelectUtil.initWithNav(title: "配置菜单查看", allArr: allArr, backClosure: cle)
            topViewController.present_FullScreen(to: vc)
            
            
             
                
              
        
            
            
        }
        self.view.addSubview(yyyBtn)
        yyyBtn.snp.makeConstraints { make in
            make.width.height.equalTo(dicBtn)
            make.top.equalTo(ppBtn.snp.bottom).offset(10)
             make.right.equalTo(oridicBtn)
         }
        yyyBtn.addTouchUpInSideAction { _ in
            
            self.leftNavBackClick(nil)
           
            let topViewController = RouterUtils.currentTopViewController()!
            if topViewController.isKind(of: ConfigMenuForm.self) {
                
                let vc = topViewController as! ConfigMenuForm
                let au = vc.tempAuditParamC!.info.formItems.filter { $0.perm == "E" }
            
                let ddds = au.compactMap{"\($0.title.unwrap) -\($0.columnName.unwrap) - \($0.perm.unwrap)" }
                 let dj =  ddds.joined(separator: "\n")
 
                alertUtil(vc, title: "渔美康编辑字段",message: dj, operateS: [nameAction(name: "确定", action: { _ in
                    
                })])
                
            } else {
                KSToast("非配置菜单界面")
            }
            
 
            
            
        }
        self.view.addSubview(zzzBtn)
        zzzBtn.snp.makeConstraints { make in
            make.width.height.equalTo(dicBtn)
            make.top.equalTo(yyyBtn.snp.bottom).offset(10)
             make.right.equalTo(oridicBtn)
         }
        zzzBtn.addTouchUpInSideAction { _ in
            
            self.leftNavBackClick(nil)
           
            let topViewController = RouterUtils.currentTopViewController()!
            if topViewController.isKind(of: ConfigMenuForm.self) {
                
                let vc = topViewController as! ConfigMenuForm
                let au = vc.tempAuditParamC!.info.formItems.filter { $0.perm == "R" }
            
                let ddds = au.compactMap{"\($0.title.unwrap) -\($0.columnName.unwrap) - \($0.perm.unwrap)" }
                 let dj =  ddds.joined(separator: "\n")
 
                alertUtil(vc, title: "渔美康只读字段",message: dj, operateS: [nameAction(name: "确定", action: { _ in
                    
                })])
                
            } else {
                KSToast("非配置菜单界面")
            }
            
 
            
            
        }
        self.view.addSubview(cccBtn)
        cccBtn.snp.makeConstraints { make in
            make.width.height.equalTo(dicBtn)
            make.top.equalTo(zzzBtn.snp.bottom).offset(10)
             make.right.equalTo(oridicBtn)
         }
        cccBtn.addTouchUpInSideAction { _ in
            
            self.leftNavBackClick(nil)
           
            let topViewController = RouterUtils.currentTopViewController()!
            if topViewController.isKind(of: ConfigMenuForm.self) {
                
                let vc = topViewController as! ConfigMenuForm
                let au = vc.tempAuditParamC!.info.formItems
            
                let ddds = au.compactMap{"\($0.title.unwrap) -\($0.columnName.unwrap) - \($0.perm.unwrap)" }
                 let dj =  ddds.joined(separator: "\n")
 
                alertUtil(vc, title: "渔美康所有字段",message: dj, operateS: [nameAction(name: "确定", action: { _ in
                    
                })])
                
            } else {
                KSToast("非配置菜单界面")
            }
            
 
            
            
        }
    }
    
}
#endif

final class TempUDTool {
  
    private let  dynamicMenuFlag = "dynamicMenuFlag"
    private let  moduleID = "moduleID"
    private let  derecNM = "derecNM"
    private let  showType = "showType"

    private init() {}
    
    
   
    
    static let shared = TempUDTool()
    
    // 显示方式
    func SetShowType(_ str:String) {
        userDefault.set(str, forKey: showType)
    }
    func GetShowType() -> String {
        let str = (userDefault.value(forKey: showType) as? String) ?? "0"
        return str
    }
    // 动态菜单版本
    func SetDynamicMenuFlag(_ str:String) {
        userDefault.set(str, forKey: dynamicMenuFlag)
    }
    func GetDynamicMenuFlag() -> String {
        let str = (userDefault.value(forKey: dynamicMenuFlag) as? String) ?? "product"
        return str
    }
      // moduleID
    func SetmoduleID(_ str:String) {
        userDefault.set(str, forKey: moduleID)
    }
    func GetmoduleID() -> String {
        let str = (userDefault.value(forKey: moduleID) as? String) ?? ""
        return str
    }
    // derecNM
    func SetderecNM(_ str:String) {
        userDefault.set(str, forKey: derecNM)
    }
    func GetderecNM() -> String {
        let str = (userDefault.value(forKey: derecNM) as? String) ?? ""
        return str
    }
   
}
